home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / utilz20x.zip / STD2EXT / STD2EXT.CPP next >
C/C++ Source or Header  |  1997-04-13  |  3KB  |  117 lines

  1. /*
  2.  * This file is part of Utiliteez v1.00.R1
  3.  *
  4.  * Copyright (c) 1995, 1997 by Branislav L. Slantchev
  5.  * A fine product of Silicon Creations, Inc. (gargoyle)
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but without any warranty; without even the implied warranty of
  14.  * merchantability or fitness for a particular purpose. See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the License along with this
  18.  * library, in the file LICENSE.DOC; if not, write to the address
  19.  * below to receive a copy via electronic mail.
  20.  *
  21.  * You can reach Branislav L. Slantchev (Silicon Creations, Inc.)
  22.  * at bslantch@cs.angelo.edu. The file SUPPORT.DOC has the current
  23.  * telephone numbers and the postal address for contacts.
  24. */
  25. #pragma warn -ofp
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <sys\stat.h>
  30. #include <dir.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33.  
  34. #define MAXLINE   513
  35. #define _VERSION  "v1.0"
  36. #define isspec(c) strchr( "+*;.?", (c) )
  37.  
  38.  
  39. int
  40. main( argc, argv )
  41.      int  argc;
  42.     char *argv[];
  43. {
  44.     FILE *fin, *fout;
  45.     char buf[MAXLINE], path[MAXPATH], s[MAXLINE], tmstr[15],
  46.          fname[MAXFILE+MAXEXT], *p;
  47.     struct stat info;
  48.  
  49.     strlwr( *argv );
  50.  
  51.     fprintf( stderr, "std2ext %s Copyright (c) 1995-1997 Branislav L. Slantchev [%s]\n\n",
  52.                 _VERSION, __DATE__ );
  53.  
  54.     /* check for enough command line arguments */
  55.     if( 3 != --argc )
  56.     {
  57.         fprintf(stderr, "usage: std2ext <files.bbs> <filepath> <output>\n");
  58.         exit( EXIT_FAILURE );
  59.     }
  60.  
  61.     strlwr( *(argv+2) );
  62.  
  63.     /* open listing file */
  64.     if( !(fin = fopen( *(argv+1), "r" )) )
  65.     {
  66.         fprintf( stderr, "%s: couldn't open '%s'", *argv, *(argv+1) );
  67.         exit( EXIT_FAILURE );
  68.     }
  69.  
  70.     /* create the output file */
  71.     if( !(fout = fopen( *(argv+3), "w")) )
  72.     {
  73.         fprintf( stderr, "%s: couldn't create '%s'", *argv, *(argv+3) );
  74.         fclose( fin );
  75.         exit( EXIT_FAILURE );
  76.     }
  77.  
  78.     /* read line by line and process */
  79.     fprintf( stderr, "Massaging '%s'...", argv[1] );
  80.     for( ;; )
  81.     {
  82.         if( !fgets( buf, MAXLINE, fin ) ) break;
  83.  
  84.         /* just a description, copy it verbatim */
  85.         if( isspace(buf[0]) || isspec(buf[0]) )
  86.         {
  87.             fputs( buf, fout );
  88.             continue;
  89.         }
  90.  
  91.         /* check for file name */
  92.         sscanf( buf, "%12s", fname );
  93.         sprintf( path, "%s/%s", *(argv+2),  strlwr(fname) );
  94.         if( -1 == stat(path, &info) )
  95.         {
  96.             fprintf( stderr, "%s: warning: '%s' not found, skipped.\n",
  97.                 *argv, path );
  98.             fputs( buf, fout );
  99.             continue;
  100.         }
  101.  
  102.         /* we have the statistics, create the output string */
  103.         strftime( tmstr, 9, "%m/%d/%y", localtime( &info.st_ctime ) );
  104.         p = strchr( buf, ' ' );    *p = '\0';
  105.         for( ++p; isspace(*p); ++p ) ;
  106.         sprintf( s, "%-12s %8ld %s %s", buf, info.st_size, tmstr, p );
  107.         fputs( s, fout );
  108.     }
  109.  
  110.     /* cleanup */
  111.     fclose( fin );
  112.     fclose( fout );
  113.  
  114.     fprintf( stderr, "Done!\n" );
  115.     return 0;
  116. }
  117.